package com.sskj.pay.http;


import android.text.TextUtils;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.UploadBean;
import com.sskj.lib.util.CommonUtil;
import com.sskj.pay.bean.PayTypeResultBean;

import java.io.File;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {


    //上传图片
    public PostRequest<HttpData<UploadBean>> upload(String filePath) {
        return OkGo.<HttpData<UploadBean>>post(HttpConfig.BASE_URL + HttpConfig.UPLOAD_FILE)
                .params("file", new File(filePath));

    }

    public PostRequest<HttpData> addOrEditPayType(boolean isAdd, String type, String account, String img, String bank, String branch, String pwd) {
        PostRequest<HttpData> params = OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ADD_OR_EDIT_PAY_TYPE)
                .params("act", isAdd ? "add" : "edit")
                .params("type", type)
                .params("payment_password", CommonUtil.getFiveMd5Value(pwd))
                .params("wx", account)
                .params("alipay", account)
                .params("bank_car", account)
                .params("bank", bank)
                .params("branch", branch);
        if (TextUtils.isEmpty(img)) {
            return params;
        } else {
            if (type.equals("wx")) {
                return params
                        .params("wx_img", new File(img))
                        ;
            } else if (type.equals("alipay")) {
                return params
                        .params("ali_img", new File(img))
                        ;
            }
            return params;
        }
    }

    public PostRequest<HttpData<PayTypeResultBean>> getPayType() {
        return OkGo.<HttpData<PayTypeResultBean>>post(HttpConfig.BASE_URL + HttpConfig.PAY_TYPE)

                ;
    }

    public PostRequest<HttpData> togglePayType(String var, String type) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.TOGGLE_PAY_TYPE)
                .params("val", var)
                .params("type", type)

                ;
    }
}
